
*------------------
* Prepare working space
*------------------

set more off
clear


*------------------
* Open cleaned and operationalized survey data
*------------------

use "SL_survey_analysis.dta", clear


**-----------------------
* Data management for the dependent variables
*-----------------------


** Model 1
		recode d9_b_ethnic_rel_since_2009 (1/2=1) (3=2) (4/5=3), gen(d9_b_ethnic_rel_since_2009_3)
		tab d9_b_ethnic_rel_since_2009_3 

** Model 2
		recode d9_a_security_since_2009 (1/2=1) (3=2) (4/5=3), gen(d9_a_security_since_2009_3)
		tab d9_a_security_since_2009_3 
		

** Model 3
		recode d9_d_freedom_speech_since_2009 (1/2=1) (3=2) (4/5=3), gen(d9_d_freedom_speech_since_2009_3)
		tab d9_d_freedom_speech_since_2009_3 

** Model 4
		recode d9_c_gov_fair_since_2009 (1/2=1) (3=2) (4/5=3), gen(d9_c_gov_fair_since_2009_3)
		tab d9_c_gov_fair_since_2009_3


*-----------------------
* Summary Statistics Table
*-----------------------

#delimit ;
estpost sum 	d9_b_ethnic_rel_since_2009_3
				d9_a_security_since_2009_3
				d9_d_freedom_speech_since_2009_3
				d9_c_gov_fair_since_2009_3	
				a11_peace_trend
				a3_ethnic_sinhalese
				a3_ethnic_tamil_moors 		
				x4_gender 					
				a1_age						
				age2						
				education_low 
				education_high				
				a7_econ_own_condition			
				a9_econ_own_vs_all				
				e4_phys_harm_war				
				c1_c2_consumption_traditional  	
				c1_c2_consumption_online		
				d6_ethnic_rel_since_2015
				d10_crackdown_peace		
				d11_organize_defend
				a15_a_neighbor_relig		
				a15_b_neighbor_ethn			
				c5_media_investigate		
				c7_media_censor				
				f1_a_threat_leaflet 
				f1_b_threat_peace_demo 
				f1_c_threat_strike 
				f1_d_threat_destruction 
				f1_e_threat_harm_opponents 
				f1_f_threat_attack_state_rep 
				f1_g_threat_attack_bystander
;
#delimit cr
eststo sumstats
*
#delimit ;
esttab sumstats using "table_sumstats.tex", replace 
		cells("count(fmt(0) label(Obs.)) mean(fmt(2) label(Mean)) sd(fmt(2) label(Std. dev.)) min(fmt(2) label(Min.)) max(fmt(2) label(Max.))")
		noobs nomtitle nonumber booktabs 
		coeflabels(
				d9_b_ethnic_rel_since_2009_3	 "Improvement of ethnic relations since 2009"
				d9_a_security_since_2009_3		 "Improvement of security since 2009"
				d9_d_freedom_speech_since_2009_3 "Perceived freedom of speech since 2009"
				d9_c_gov_fair_since_2009_3		 "Fair treatment by government since 2009"
				a11_peace_trend					"Evaluation of peace prospects"
				a3_ethnic_sinhalese				"Sinhalese"			
				a3_ethnic_tamil_moors 			"Tamil-Moor"
				x4_gender 						"Female"
				a1_age							"Age"
				age2							"Age\textsuperscript{2}"
				education_low 					"Low education"
				education_high					"High education"
				a7_econ_own_condition			"Absolute economic situation"
				a9_econ_own_vs_all				"Relative economic situation"
				e4_phys_harm_war				"Harmed in war"
				c1_c2_consumption_traditional  	"Use traditional media"
				c1_c2_consumption_online		"Use online media"
				d6_ethnic_rel_since_2015		"Improvement of ethnic relations since 2015"
				d10_crackdown_peace				"Crackdown on extremists would promote peace"
				d11_organize_defend				"Minorities should organized self-defense"
				a15_a_neighbor_relig			"Appreciation for neighbour of other religion"
				a15_b_neighbor_ethn				"Appreciation for neighbour of other ethnicity"
				c5_media_investigate			"Preference for investigative media"
				c7_media_censor					"Preference for media freedom"
				f1_a_threat_leaflet				"Threat from leaflets"
				f1_b_threat_peace_demo			"Threat from strikes"
				f1_c_threat_strike				"Threat from demonstrations"
				f1_d_threat_destruction			"Threat from property damage"
				f1_e_threat_harm_opponents		"Threat from attacking political opponents"
				f1_f_threat_attack_state_rep	"Threat from attacking state representatives"
				f1_g_threat_attack_bystander	"Threat from attacking bystanders"
				)
		refcat(a3_ethnic_sinhalese "\midrule%" d6_ethnic_rel_since_2015 "\midrule%")		
		labcol2(
			"Ordered" "Ordered" "Ordered" "Ordered" "Binary"
			""
			"Binary" "Binary" "Binary"
			"Continuous" "Continuous" 
			"Binary" "Binary"
			"Ordered" "Ordered" 
			"Binary" "Binary" "Binary"
			""
			"Ordered"
			"Binary" "Binary" "Binary" "Binary" "Binary" "Binary"
			"Ordered" "Ordered" "Ordered" "Ordered" "Ordered" "Ordered" "Ordered"
			,title("Type"))
		addnotes("")
		title("Summary")
		substitute(\_ _)
		fragment
		prehead(
		\begin{table}[htbp]\centering
		\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
		\caption{Summary statistics \label{sumstats}}
		\resizebox{16cm}{!}{	
		\begin{tabular}{lc*{1}{ccccc}}
		\toprule
		)
		postfoot(
		\bottomrule
		\end{tabular}
		}
		\end{table}		
		)
		;
#delimit cr






*-----------------------
* Correlation table
*-----------------------


#delimit ;
local corrvariables="
				a3_ethnic_sinhalese	
				x4_gender 					
				a1_age
				education_low 
				education_high				
				a7_econ_own_condition
				a9_econ_own_vs_all
				e4_phys_harm_war
				c1_c2_consumption_traditional  
				c1_c2_consumption_online
				"
;
# delimit cr	

corr `corrvariables'

estpost corr `corrvariables', matrix listwise
eststo corrstats


#delimit ;
esttab corrstats using "table_corrmatrix.tex", replace 
		unstack not noobs nostar nomtitle nonumber booktabs compress b(3) 	
		coeflabels(
				a3_ethnic_sinhalese				"Sinhalese"
				x4_gender						"Female"
				a1_age							"Age"
				education_low 					"Low education"
				education_high					"High education"
				a7_econ_own_condition			"Abs. econ. situation"
				a9_econ_own_vs_all				"Rel. econ. situation"
				e4_phys_harm_war				"Harmed in war"
				c1_c2_consumption_traditional	"Use trad. media"
				c1_c2_consumption_online		"Use online media"
		)
		eqlabels(
					"Sinhalese"
					"Female"
					"Age"
				 	"Low education"
					"High education"
					"Abs. econ. situation"
					"Rel. econ. situation"
					"Harmed in war"
					"Use trad. media"
					"Use online media"
		)
		fragment
		prehead(
		\begin{table}[htbp]\centering
		\caption{Correlation matrix \label{corrmat}}
		\begin{adjustbox}{angle=90}
		\resizebox{18cm}{!}{	
		\begin{tabular}{p{4cm} p{1.4cm} p{1.4cm} p{1.4cm} p{1.4cm} p{1.4cm} p{1.4cm} p{1.4cm} p{1.4cm} p{1.4cm} p{1.4cm}} 
		\toprule
		)
		postfoot(
		\bottomrule
		\end{tabular}
		}
		\end{adjustbox}
		\end{table}		
		)	
		;
#delimit cr
















